package gupaoedu.prototype;

import gupaoedu.prototype.Course;
import gupaoedu.prototype.Person;

import java.util.ArrayList;
import java.util.List;

/**
 * gupaoedu
 * linwenjie
 * 2019-06-21
 * 测试类
 */
public class PrototypeTest {
    public static void main(String[] args) {
        try {
            //系列课程
            List<Course> courses = new ArrayList<>();
            courses.add(new Course("Java", "李老师"));
            courses.add(new Course("Python", "李老师"));

            Person person = new Person();
            person.setName("张三");
            person.setCourses(courses);


            //李四同样购买了课程

            Person person1 = (Person) person.clone();
            person1.setName("李四");

            System.out.println(person == person1);
            System.out.println(person.getCourses() == person1.getCourses());


            Person person2 = (Person) person.shallowClone();
            person1.setName("王五");

            System.out.println(person == person2);
            System.out.println(person.getCourses() == person2.getCourses());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
